<?php

/**

 *

 * @package 

 * @since 1.0

 * @todo 首页、列表页面、详细页

 */

 

class IndexAction extends AllAction{



	/**

	 +----------------------------------------------------------

	 * 预处理

	 * --------------------------------

	 +----------------------------------------------------------

	 */
	/**

	 +----------------------------------------------------------

	 * 首页

	 +----------------------------------------------------------

	 */

	 function index(){

		$jiancha=$this->is_mobile_request();
		
		if($jiancha){
			$this->redirect(U('Index/indexs'));	
		}

         $jiaodian = M('jiaodian')->order('xu asc,id desc')->select();

		 $this->assign('jiaodian',$jiaodian);

			
			$list = M('anli')->where("zhuangtai=1")->order('id desc')->select();
			foreach($list as $k=>$v){
				$dian=M('news')->find($v['fenlei']);
				$list[$k]['fenlei']=$dian['name'];
				$dianhua=$v['dianhua'];
				$str1 = substr($dianhua,0,3);
				$str2 = substr($dianhua,-2);
				$list[$k]['dianhua']=$str1."*****".$str2;
			}
			
			$this->assign('list',$list);
	
		 $this->assign('zuixin',$list[0]);

		 $zuopin=M('news')->order('xu desc,id desc')->select();
		 foreach($zuopin as $k=>$v){
		 	$zuopin[$k]['renshu']=M('anli')->where("fenlei=".$v['id']."")->count();
		 }

		 $this->assign('zuopin',$zuopin);
		 
		 $erjijiaodian=M('erjijiaodian')->find(1);

		 $this->assign('erjijiaodian',$erjijiaodian);
		 
		 $erweima=M('erjijiaodian')->find(4);

		 $this->assign('erweima',$erweima);

		 $this->display();

	 }
	 function indexs(){


         $jiaodian = M('erjijiaodian')->find(2);

		 $this->assign('jiaodian',$jiaodian);


		 $zuopin=M('news')->order('xu desc,id desc')->select();
		 foreach($zuopin as $k=>$v){
		 	$zuopin[$k]['renshu']=M('anli')->where("fenlei=".$v['id']."")->count();
		 }

		 $this->assign('zuopin',$zuopin);
		 
		 $erjijiaodian=M('erjijiaodian')->find(3);

		 $this->assign('erjijiaodian',$erjijiaodian);

		 $this->display();

	 }
 	
	//众筹号码查询
	function soudianhua() {
		$dianhua=$_POST['dianhua'];
		if($dianhua==''){
			$kehu['tishi']="1";
		}else{
			$kehu=M('anli')->where("dianhua='".$dianhua."'")->find();
			
			if($kehu){
				$dianhua=$kehu['dianhua'];
				$str1 = substr($dianhua,0,3);
				$str2 = substr($dianhua,-2);
				$kehu['dianhua']=$str1."*****".$str2;
				$dian=M('news')->find($kehu['fenlei']);
				$kehu['fenlei']=$dian['name'];
				$kehu['renshu']=M('anli')->where("fenlei=".$dian['id']."")->count();
			}else{
				$kehu['tishi']="2";
			}
			
		}
		echo json_encode($kehu);
		exit;
	}
	//search
	//报名提交
	function baomingtijiao() {
		$baoming['dianhua']=$_POST['bmdianhua'];
		$baoming['name']=$_POST['bmname'];
		$baoming['fenlei']=$_POST['fenleiid'];
		$baoming['time']=time();
		$baoming['choujiang']="众筹成功，已进入抽奖池";
		
		if($baoming['name']==''){
			$tishi="2"; echo $tishi; exit;
		}
		if($baoming['dianhua']==''){
			$tishi="1"; echo $tishi; exit;
		}
		$shifou=M('anli')->where("dianhua=".$baoming['dianhua']."")->find();
		if($shifou){
			$tishi="3"; echo $tishi; exit;
		}
		if(M('anli')->add($baoming)){
			$tishi="99";
		}else{
			$tishi="100";
		}
			
		
		echo $tishi;
		exit;
	}
	//search

	function search(){

		 $name=$_REQUEST['name'];

		 $this->assign('name',$name);



		import("@.ORG.Page");

		$count	= M('cpxilie')->where("name like '%$name%'")->count();

		

		$Page	= New Page($count,16);



		$show	= $Page->show();

		$list = M('cpxilie')->where("name like '%$name%'")->order('xu asc,id desc')->limit($Page->firstRow.','.$Page->listRows)

						     ->select();

	    $this->assign('list', $list);

		$this->assign('page', $show);



		$this->display(); 	

	}

	

	

	



} 